home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1996 October
/
MACPOWER-1996-10.ISO.7z
/
MACPOWER-1996-10.ISO
/
AMUG
/
Internet_31
/
Analog 1.9b6d
/
Analog 1.9b6d ト
/
newlog.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-06
|
6KB
|
175 lines
/* NEWLOG.C - Version 1.1 4/23/96
Copyright (c) 1996 by Jason T. Linhart
This file is freeware. You may use it and give copies to friends, so
long as you include all of the file without modification. It may not
be sold or commercially distributed without a written licence from me.
It may be included in archives, and distributed on CD-ROM or on other
formats so long as there are no charges for these services other than
shipping, handling and the cost of media. Use or distribution of this
file indicates your agreement to these terms.
Created 1/17/96 by Jason T. Linhart to replace Netscape default logger
Modeled after 'nosy.c' Netscape example of additional logging info.
Updated 2/7/96 by Jason T. Linhart to provide NCSA combined log format.
*/
/*
This NSAPI module will cause a Netscape server to produce an NCSA combined
format log file instead of the NCSA common format log it normaly creates.
This is only useful with Netscape servers, and requires various headers
supplied by Netscape. You will have to figure out how to compile and
link this file yourself based on the Netscape documentation. Then:
1. Append the following lines to your magnus.conf file:
Init fn=load-modules shlib=<your fullpath>/logger.so funcs=exlog-init,exlog-log
Init fn=exlog-init file=<your fullpath>/access
2. Edit your "obj.conf" file to comment out the existing AddLog line and
include the following line in the "<Object name=default>" section:
# AddLog fn=common-log
AddLog fn=exlog-log
3. Shut down your server, then start it up again (don't restart).
These are the fields that are logged:
DNS-name, client user name, auth user name, start time, request ( method, URL, protocol ), ¥
status, bytes, refer, client
This is exactly the same as the common log format except that refer and client are added
at the end. Your "access" log file should look like this:
cronos.mcom.com - - [11/Aug/1995:23:48:05 -0700] "GET / HTTP/1.0" 304 - "http://coltrane.mcom.com:1995/https-1967/bin/restart?" "Mozilla/1.1N (Macintosh; I; 68K)"
*/
/* standard headers for SAFs */
#include "base/pblock.h"
#include "base/session.h"
#include "frame/req.h"
/* specific headers useful for logging functions */
#include "base/util.h" /* is_mozilla, getline */
#include "frame/protocol.h" /* protocol_start_response */
#include "base/file.h" /* system_fopenRO */
#include "base/buffer.h" /* filebuf */
#include "frame/log.h" /* log_error */
#include <stdio.h>
#include <unistd.h>
#include <time.h>
/* File descriptor to be shared between the processes */
static SYS_FILE logfd = SYS_ERROR_FD;
/* function to shut down the logging; will be called on server restart */
void
exlog_term(void *parameter)
{
system_fclose(logfd);
logfd = SYS_ERROR_FD;
}
/* init function for logging */
int
exlog_init(pblock *pb, Session *sn, Request *rq)
{
/* file parameter */
char *fn = pblock_findval("file", pb);
if (!fn) {
pblock_nvinsert("error", "Exlog-init: please supply a file name", pb);
return REQ_ABORTED;
}
logfd = system_fopenWA(fn);
if (logfd == SYS_ERROR_FD) {
pblock_nvinsert("error", "Exlog-init: unable to open file", pb);
return REQ_ABORTED;
}
/* Close log file when server is restarted */
magnus_atrestart(exlog_term, NULL);
return(REQ_PROCEED);
}
/* actual logging function! */
int
exlog_log(pblock *pb, Session *sn, Request *rq)
{
/* working variables */
struct tm date;
time_t timer;
char *req_str, *dns, *uname, time_str[32+10], status[6], *length;
char *from, *agent, *referer, *empty="-¥0";
char *logmsg, *temp;
long offset;
int len;
/*
Stuff we want to log:
DNS-name, client user name, auth user name, start time,
request ( method, URL, protocol ), status, bytes, client, refer
*/
dns = session_dns(sn);
if (!dns) /* use IP if no DNS found */
dns = pblock_findval("ip", sn->client);
from = pblock_findval("from", rq->headers);
uname = pblock_findval("auth-user", rq->vars);
timer=time((void *)0);
date = *localtime(&timer);
if (strftime(time_str,32,"[%d/%b/%Y:%H:%M:%S ",&date)) {
if (daylight && date.tm_isdst>0)
offset=altzone;
else offset=timezone;
offset/=60;
if (offset<0)
offset = -offset;
else strcat(time_str,empty);
sprintf(time_str+strlen(time_str),"%02d%02d]",offset/60,offset%60);
}
else strcpy(time_str,empty);
req_str = pblock_findval("clf-request", rq->reqpb);
temp = pblock_findval("status", rq->srvhdrs);
if (temp && *temp) {
status[0]=temp[0];
status[1]=temp[1];
status[2]=temp[2];
status[3]=0;
}
else strcpy(status,empty);
length = pblock_findval("content-length", rq->srvhdrs);
agent = pblock_findval("user-agent", rq->headers);
referer = pblock_findval("referer", rq->headers);
/* make NULL results be a dash */
if (!dns || !*dns) dns=empty;
if (!from || !*from) from=empty;
if (!uname || !*uname) uname=empty;
if (!req_str || !*req_str) req_str=empty;
if (!length || !*length) length=empty;
if (!agent) agent="";
if (!referer) referer="";
/* print it! cronos.mcom.com - - [11/Aug/1995:23:48:05 -0700] "GET / HTTP/1.0" 304 - */
logmsg=(char *)MALLOC(strlen(dns)+strlen(from)+strlen(uname)+strlen(time_str)+strlen(req_str)+
strlen(status)+strlen(length)+strlen(agent)+strlen(referer)+18);
len=util_sprintf(logmsg, "%s %s %s %s ¥"%s¥" %s %s ¥"%s¥" ¥"%s¥"¥n", dns, from, uname,
time_str, req_str, status, length, referer, agent);
system_fwrite_atomic(logfd, logmsg, len);
FREE(logmsg);
return(REQ_PROCEED);
}
/* END OF NEWLOG.C */